package io;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Objects;

public class Student implements Serializable {
    private String name;
    private int age;
    private String gender;
    /*
    当一个属性被关键字transient修饰后,当这个对象被序列化时,此属性会被忽略
    忽略不必要的属性值可以达到对象序列化瘦身的目的
    可以减少磁盘开销或提高网络传输效率
     */
    private transient String[] otherInFo;

    public Student() {
    }

    public Student(String name, int age, String gender, String[] otherInFo) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.otherInFo = otherInFo;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return gender
     */
    public String getGender() {
        return gender;
    }

    /**
     * 设置
     * @param gender
     */
    public void setGender(String gender) {
        this.gender = gender;
    }

    /**
     * 获取
     * @return otherInFo
     */
    public String[] getOtherInFo() {
        return otherInFo;
    }

    /**
     * 设置
     * @param otherInFo
     */
    public void setOtherInFo(String[] otherInFo) {
        this.otherInFo = otherInFo;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name) && Objects.equals(gender, student.gender) && Arrays.equals(otherInFo, student.otherInFo);
    }

    @Override
    public int hashCode() {
        int result = Objects.hash(name, age, gender);
        result = 31 * result + Arrays.hashCode(otherInFo);
        return result;
    }

    public String toString() {
        return "Student{name = " + name + ", age = " + age + ", gender = " + gender + ", otherInFo = " + otherInFo + "}";
    }
}
